<link rel="stylesheet" type="text/css" href="/css/admingoods/publish.css?v=0.0.0" media="all" />		
<script type="text/javascript" src="/js/admingoods/publish_update.js?v=0.0.0" ></script>
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=10ci2Syk2wU83q4CA6KzmOxw5LW32xHO"></script>
<script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=10ci2Syk2wU83q4CA6KzmOxw5LW32xHO"></script>
<script type="text/javascript" charset="utf-8" src="/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<div class="pt15 pl15">当前位置：<span class="layui-breadcrumb"><a href="/">首页</a><a href="/admingoods/default/index">商品管理</a><a><cite>修改商品</cite></a></span></div>
<div class="layui-fluid publish-outter">
    <div class="layui-card p30">		
		<div class="border-b pb15 f22">修改商品</div>
		<div class="layui-card-body pt30 pb15">	
			<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
				<ul class="layui-tab-title">
					<li class="layui-this">基本信息</li>
					<?php if($data['goods']['first_cate']==1){ ?>
					<li>地图标注</li>
					<?php }?>
					<li>详细介绍</li>
				</ul>
				<div class="layui-tab-content">
				  <div class="layui-tab-item layui-show">
						<div class="layui-row">
							<div class="layui-col-xs12 layui-col-md8 layui-col-lg6">
								<input type="hidden" id="goodsid" value="<?= $data['goods']['id']?>"/>
								<input type="hidden" id="first_cate" value="<?= $data['goods']['first_cate']?>"/>
								<input type="hidden" id="second_cate" value="<?= $data['goods']['second_cate']?>"/>
								<input type="hidden" id="third_cate" value="<?= $data['goods']['third_cate']?>"/>
								<div class="layui-form-item">
									<div class="goods_label"><span class="must-input">*</span>商品名称：</div>
									<div class="layui-input-block">
										<input type="text" data-must="1" id="goodsname" name="goodsname" value="<?= $data['goods']['name'] ?>"  class="layui-input"/>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="goods_label"><span class="must-input">*</span>商品价格：</div>
									<?php if($data['goods']['have_package']==1){?>
										<div class="layui-input-inline">
											<input type="text" data-must="1" id="price" name="price" value="0" <?= $data['goods']['first_cate']==1?"disabled":"" ?> class="layui-input"/>
										</div>
										<div class="layui-form-mid layui-word-aux">
											<span id="goodsprice_format">元/<?= $data['goods']['first_cate']==1?"月":"件" ?></span>
										</div>
									<?php }else{?>
										<div class="layui-input-inline">
											<input type="text" data-must="1" id="price" name="price" value="<?= $data['goods']['price'] ?>" class="layui-input"/>
										</div>
										<div class="layui-form-mid layui-word-aux">
											<span id="goodsprice_format">元/<?= $data['goods']['first_cate']==1?"月":"件" ?></span>
										</div>
									<?php }?>						
								</div>
								<?php if($data['goods']['first_cate']==1){ ?>
								<div class="layui-form-item" id="install-price-line">
									<div class="goods_label"><span class="must-input">*</span>安装维护费：</div>
										<?php if($data['goods']['have_package']==1){?>
											<div class="layui-input-inline">
												<input type="text" data-must="1" id="install_price" name="install_price" value="0" disabled="disabled" class="layui-input"/>
											</div>
											<div class="layui-form-mid layui-word-aux">元/月</div>
										<?php }else{?>
											<div class="layui-input-inline">
												<input type="text" data-must="1" id="install_price" name="install_price" value="<?= $data['goods']['install_price'] ?>" class="layui-input"/>
											</div>
											<div class="layui-form-mid layui-word-aux">元/月</div>
										<?php }?>
									
								</div>
								<div class="layui-form-item" id="areanum-line">
									<div class="goods_label"><span class="must-input">*</span>面积：</div>
									<div class="layui-input-inline">
										<input type="text" data-must="1" id="area_num" name="area_num" value="<?= $data['goods']['area_num'] ?>" class="layui-input"/>
									</div>
									<div class="layui-form-mid layui-word-aux">平米</div>
								</div>
								<?php }?>
								
								<?php 
								$is_must_font ='<span class="must-input">*</span>';
								foreach($data['attr_input'] as $attr_input){
								if($attr_input['type'] == 0){ ?>
								<div class="layui-form-item">
									<div class="goods_label"><?= $attr_input['is_must'] == 1 ? $is_must_font:"" ?><?= $attr_input['name']?>：</div>
									<div class="layui-input-block_backset" data-name="<?= $attr_input['name']?>" data-must="<?= $attr_input['is_must']?>" data-type="<?= $attr_input['type']?>">
										<input type="text" name="attr_<?= $attr_input['id']?>" id="attr_<?= $attr_input['id']?>" value="<?= $attr_input['val']?>" data-name="<?= $attr_input['name']?>"  class="layui-input"/>
									</div>
								</div>
								<?php }
								if($attr_input['type'] == 1){ ?>
									<div class="layui-form-item">
										<div class="goods_label"><?= $attr_input['is_must'] == 1 ? $is_must_font:"" ?><?= $attr_input['name']?>：</div>
										<div class="layui-input-block_backset" data-name="<?= $attr_input['name']?>" data-must="<?= $attr_input['is_must']?>" data-type="<?= $attr_input['type']?>">
											<select name="attr_<?= $attr_input['id']?>" id="attr_<?= $attr_input['id']?>" data-name="<?= $attr_input['name']?>">
												<?php foreach($attr_input['option'] as $option){ ?>
												<option value="<?= $option['id']?>" <?= $option['selected']==1 ? 'selected':''?>><?= $option['val']?></option>
												<?php } ?>
											</select>
									</div>
									</div>
									<?php } 
									if($attr_input['type'] == 2){ ?>
									<div class="layui-form-item">
										<div class="goods_label"><?= $attr_input['is_must'] == 1 ? $is_must_font:"" ?><?= $attr_input['name']?>：</div>
										<div class="layui-input-block_backset" data-name="<?= $attr_input['name']?>" data-must="<?= $attr_input['is_must']?>" data-type="<?= $attr_input['type']?>">
											<?php foreach($attr_input['option'] as $option){ ?>
											<input id="option_<?= $option['id']?>" type="checkbox" name="attr_<?= $attr_input['id']?>[]" value="<?= $option['id']?>" <?= $option['checked']==1 ? 'checked':''?>>
											<label for="option_<?= $option['id']?>"><?= $option['val']?></label>
											<?php } ?>
										</div>
									</div>
									<?php } ?>
								<?php } ?>
								
								<div class="layui-form-item" id="package-choose-line">
									<div class="goods_label"><span class="must-input">*</span>是否多套餐：</div><div class="layui-input-block">
										<select name="have_package" data-must="1" id="have_package" <?= $data['goods']['first_cate']===1 ? 'disabled':'' ?>>
											<option value="0" <?= $data['goods']['have_package']==0 ? 'selected':'' ?>>否</option>
											<option value="1" <?= $data['goods']['have_package']==1 ? 'selected':'' ?>>是</option>
										</select>								
										<?php if($data['goods']['first_cate']==1){ ?>
										广告位类型的商品不可编辑套餐
										<?php } ?>
									</div>
								</div>
								<div class="publish-package-item-line" id="package-area-outter">
									<div class="goods_label">&nbsp;</div>
									<div class="layui-input-block">
										<div id="package-area-container">
											<textarea name="package" id="package" class="layui-textarea" placeholder="" <?= $data['goods']['first_cate']==1 ? 'disabled':'' ?>><?= $data['package']?></textarea>
											<div id="package-description" class="package-description">
												<?php if($data['goods']['first_cate']==1){ ?>
												广告位类型的商品不可编辑套餐
												<?php }else{?>
												每一行代表一个套餐，格式：套餐名称 价格 库存，如：套餐一 500 100
												<?php } ?>
											</div>
										</div>
									</div>
								</div>
								<div id="attr-area-outter"></div>
								
								<div class="publish-img-line">
									<div class="goods_label"><span class="must-input">*</span>商品图片：</div>
									<div class="layui-input-block">
										<blockquote class="layui-elem-quote layui-quote-nm">
											<div class="uploadimg-display-outter" id="uploadimg-display-outter">
												<?php foreach($data['goods']['imgs'] as $img){ ?>
													<div class="uploadimg-result-single">
														<img src="<?= $img['src']?>" data-url="<?= $img['src']?>" class="uploadimg-display">
														<div class="remove-outter">
															<span class="uploadeimg-remove">移除</span>
														</div>
													</div>
												<?php } ?>
												<div class="filebutton">
													<div class="content">
														<div>
															<i class="layui-icon">&#xe624;</i><p>添加图片</p>
														</div>
													</div>
													<input type="file" style="cursor: pointer;" id="goodsimg-upload" multiple="multiple" name="goodsimg[]" accept="image/*"/>
												</div>
											</div>							
										</blockquote>
									</div>
								</div>
							</div>
						</div>
				  </div>
					<?php if($data['goods']['first_cate']==1){ ?>
						<div class="layui-tab-item">
							<div id="location-line">
								<input type="hidden" id="longitude" name="longitude" value="<?= $data['goods']['longitude']?>" placeholder="经度">
								<input type="hidden" placeholder="经度" value="<?= $data['goods']['latitude']?>" id="latitude" name="latitude">
								<input type="hidden" value="<?= $data['goods']['region_area']?>" id="region_area" name="region_area">
								<input type="hidden" value="<?= $data['goods']['address']?>" id="address" name="address">
								<div id="allmap"></div>	
							</div>
						</div>
					<?php } ?>
					<div class="layui-tab-item">
						<script id="introduction" type="text/plain" name="gdesc"></script>
						<div class="layui-hide" id="introduction_history" ><?= $data['goods']['introduction']?></div>
					</div>
			  </div>
			</div>
			<div class="pt30 border-t text-c">
				<button type="submit" class="layui-btn layui-btn-normal" id="publish-submit-button">提交</button>
				<a class="layui-btn layui-btn-primary" href="/admingoods/default/index">取消</a>					
			</div>	
		</div>
	</div> 
</div>

<script type="text/javascript">
$(document).ready(function(){

    layui.use('laydate', function(){
      var laydate = layui.laydate;  
      //执行一个laydate实例
      laydate.render({
        elem: '#order_endtime' //指定元素
      });
    });
    if($("#first_cate").val()==1){
        var map = new BMap.Map("allmap");          // 创建地图实例
        var initLat = 39.916527;
        var initLng = 116.397128;
        var point = new BMap.Point(<?= $data['goods']['longitude']?>, <?= $data['goods']['latitude']?>);  // 创建点坐标  
        map.centerAndZoom(point, 15);  
        // var marker = new BMap.Marker(point);        // 创建标注    
        // map.addOverlay(marker);                     // 将标注添加到地图中			
        map.enableScrollWheelZoom();                   // 启用滚轮放大缩小 

        mk = new BMap.Marker(point);
        mk.addEventListener("dragend", showInfo);
        mk.enableDragging();    //可拖拽		                
        getAddress(point);
        map.addOverlay(mk);//把点添加到地图上  
        map.panTo(point);

        //绑定Marker的拖拽事件
        function showInfo(e){
			var gc = new BMap.Geocoder();
			gc.getLocation(e.point, function(rs){
				var addComp = rs.addressComponents;
				//var address = addComp.province +  addComp.city + addComp.district + addComp.street + addComp.streetNumber;//获取地址
				var region_area = addComp.province +' '+  addComp.city +' '+  addComp.district;//获取地址
				var address = addComp.street +' '+ addComp.streetNumber;//获取地址		
				//画图 ---》显示地址信息
				var label = new BMap.Label(address,{offset:new BMap.Size(20,-10)});
				map.removeOverlay(mk.getLabel());//删除之前的label 	
				mk.setLabel(label);
				window.parent.$('#longitude').val(e.point.lng);
				window.parent.$('#latitude').val(e.point.lat);	
				window.parent.$('#region_area').val(region_area);
				window.parent.$('#address').val(address);

			 });
        }		        
        //获取地址信息，设置地址label
        function getAddress(point){
			var gc = new BMap.Geocoder();		            
			gc.getLocation(point, function(rs){
				var addComp = rs.addressComponents;
				var address =  addComp.province +  addComp.city + addComp.district + addComp.street + addComp.streetNumber;//获取地址
				//画图 ---》显示地址信息
				var label = new BMap.Label(address,{offset:new BMap.Size(20,-10)});
				map.removeOverlay(mk.getLabel());//删除之前的label 
				mk.setLabel(label);

			 });

        }
    }
});
</script>